

#include <boost/thread/thread.hpp>

#include "slim_server.hpp"

namespace	sakcab	{


SlimServer::SlimServer( sakcab::server::StoreService* store_p, int slim_interval_s )
		:	_store_p( store_p ),
			_slim_interval( slim_interval_s ),
			_will_stop( false )
{
	if (_slim_interval < DEFAULT_SLIM_INTERVAL_s ) {
		_slim_interval = DEFAULT_SLIM_INTERVAL_s;
	}
}


void
SlimServer::stop( void )
{
	_will_stop = true;
}


void
SlimServer::run( void )
{
	int	count_down = 0;

	while( !_will_stop ) {
		if ( count_down <= 0 ) {
			_store_p->slim();

			count_down = _slim_interval;
		}

		boost::this_thread::sleep(boost::posix_time::milliseconds(1000));
		--count_down;
	}
}


}	//// namespace sakcab

